<?php


function rate(){
  if(func_num_args() != 1){
    list($a,$b) = explode(" " ,microtime());
	return $b+$a;
  }else{
	list($aa,$bb) = explode(" " ,microtime());
	$end = ($bb+$aa) - func_get_arg(0);
	return  number_format($end,5);
  }
}


function url(){
 $url ="http://";
 $q= empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : "?".$_SERVER['QUERY_STRING'];
 $url .= $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].$q;
 return $url;
}




function eachClss($str)
{
	$list = get_class_methods("ActionControl");
	return in_array($str,$list) ? 1 : 0;	
}


function stageRouter()
{
	$err = array( ';', ':', ',', '&&', '||', 'AND', 'OR', 'SELECT', 'FROM', 'UPDATE', 'DELETE', 'UNION' );
	$parameter = explode("/", $_GET['q']);

	for($i=0 ; $i < count($parameter); $i++) {
		if (empty($parameter[$i])) {
			unset($parameter[$i]); 
			continue;
		}

		if(in_array(strtoupper($parameter[$i]), $err)) {
			return 1;
			break;
		}	
	}

	return $parameter;	
}


//日期倒计时
function countdown($timestamp) { 
	$date =time() - $timestamp; 
	$day = $date/60/60/24; 
	$days = (int)$day; 
	$hour = $date/60/60 - $days*24; 
	$hours = (int)$hour; 
	$minute = $date/60 - $days*24*60 - $hours*60; 
	$minutes = (int)$minute; 
	$second = $date - $days*24*60*60 - $hours*60*60 - $minutes*60; 
	$seconds = (int)$second; 
	$dayes = $days == 0 ? '' : $days.'天';
	$hours = $hours == 0 ? '' : $hours."小时"; 
	$minutes = $minutes == 0 ? '' : $minutes."分钟"; 
	$seconds = $seconds == 0 ? '' : $seconds."秒"; 
	$result = array($days,$dayes,$hours,$minutes,$seconds); 
	return $result; 
}


function message($str , $back = "" ,$isShow = false){
       
	if( empty($_SESSION) ) {
		$url = '' ; 
	} else {
		$url = $_SESSION['url'];
    }

    $back = empty($back) ? $url : $back;
    
	header('Content-Type: text/html; charset=utf-8');	
	$html = '<center style="margin-top:60px;width: 300px; background: #FCFCFC; border:solid 1px #ddd; padding: 5px; line-height: 25px;">';
	$html .= '<span style="color:#FF6600; font-size: 14px; font-weight: 600">[提示信息]</span>';
	$html .=  true == $isShow  ? ' ' : '&nbsp;&nbsp;&nbsp;<a href="'.$back.'">返回</a>';
	$html .= '<div style="background-color: #FFFFDD; border:solid 1px #ddd; margin: 3px; text-align:left; padding: 3px;">';
	$html .= $str.'</div></center>';
	echo $html;
} 

?>
